package com.yanqu.road.dao.impl.activity.dafuweng;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.dafuweng.DFWMapConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class DFWMapConfigDaoImpl extends TempDao {

    private static final String sql = "select * from t_s_monopoly_map where activityId = ? order by `level` asc";

    public List<DFWMapConfig> getDFWMapConfigList(int activityId) {
        ResultSet rs = null;
        CallableStatement call = null;
        List<DFWMapConfig> list = new ArrayList<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                DFWMapConfig config = new DFWMapConfig();
                config.setMapId(rs.getInt("id"));
                config.setMapName(rs.getString("name"));
                config.setIcon(rs.getString("icon"));
                config.setUnlockGold(rs.getInt("needGold"));
                config.setSkill(rs.getInt("eventId"));
                config.setResource(rs.getString("resource"));
                config.setLevel(rs.getInt("level"));
                list.add(config);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

}
